import java.util.ArrayDeque;
import java.util.LinkedList;

public class L101 {
    public static void main(String[] args) {
        TreeNode treeNode = new TreeNode(2);
        new Solution().isSymmetric(treeNode);
    }

    static class Solution {
        public boolean isSymmetric(TreeNode root) {
            boolean compare = compare(root.left, root.right);
            return compare;
        }

        private boolean compare(TreeNode left, TreeNode right) {
            if (left == null && right != null) {
                return false;
            }
            if (left != null && right == null) {
                return false;
            }
            if (left == null && right == null) {
                return true;
            }
            if (left.val != right.val) {
                return false;
            }
            boolean compare = compare(left.left, right.right);
            boolean compare1 = compare(left.right, right.left);
            return compare && compare1;
        }

//        public boolean isSymmetric(TreeNode root) {
//            LinkedList<TreeNode> deque = new LinkedList<>();
//            deque.offer(root.left);
//            deque.offer(root.right);
//            while (!deque.isEmpty()) {
//                TreeNode left = deque.poll();
//                TreeNode right = deque.poll();
//                if (left == null && right == null) {
//                    continue;
//                }
//                if (left == null || right == null || left.val != right.val) {
//                    return false;
//                }
//                deque.offer(left.left);
//                deque.offer(right.right);
//                deque.offer(left.right);
//                deque.offer(right.left);
//
//            }
//            return true;
//        }
    }
}
